package 集合.LIST;

import java.util.ArrayList;

public class ArrayListDemo6 {
    public static void main(String[] args) {
        ArrayList<ArrayListDemo6User>list=new ArrayList<>();
        ArrayListDemo6User u1=new ArrayListDemo6User("黑马001","张三","123456");
        ArrayListDemo6User u2=new ArrayListDemo6User("黑马002","李四","12345678");
        ArrayListDemo6User u3=new ArrayListDemo6User("黑马003","王五","234qwer");
        list.add(u1);
        list.add(u2);
        list.add(u3);
        boolean falg=contains(list,"黑马001");
        int flag=getIndex(list,"黑马001");
        System.out.println(flag);
        System.out.println(falg);
    }
    public static boolean contains(ArrayList<ArrayListDemo6User>list, String id){
        for (int i = 0; i < list.size(); i++) {
            list.get(i).getID().equals(id);
        return true;
        }
    return  false;
        //return getIndex(list,id)>=0;
        //将上下两个方法合并，
    }
    //查找id所对应的索引；
   public static int getIndex(ArrayList<ArrayListDemo6User>list, String id){
        for (int i = 0; i < list.size(); i++) {
            list.get(i).getID().equals(id);
            return i;
        }
        return -1;
    }
}
